package cn.com.bocloud.dao.daoimpl;

import cn.com.bocloud.dao.UserDao;
import cn.com.bocloud.domain.User;
import cn.com.bocloud.util.JDBCUtil;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class UserDaoImpl implements UserDao {
    @Override
    public User login(String name, String password) throws Exception {
        Connection conn = JDBCUtil.getConn();
        PreparedStatement ps = conn.prepareStatement("select * from user where name=? and password=?");
        ps.setString(1,name);
        ps.setString(2,password);
        ResultSet rs = ps.executeQuery();
        while (rs.next()){
            if (rs!=null){
                User u = new User();
                String name1 = rs.getString("name");
                u.setName(name1);
                String password1 = rs.getString("password");
                u.setPassword(password1);
                return u;

            }else {
                return null;
            }
        }
        return null;
    }
}
